package com.lzy.crm.util;


import com.lzy.crm.vo.LoginInfo;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class SessionManager {
	
	private static String session_key = "loginInfoSession";
	
	
	/**
	 * 获取登陆信息
	 * @param browerSessionId :浏览器session
	 * @return
	 */
	public static LoginInfo getLoginInfo(){
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		LoginInfo loginInfo =(LoginInfo) request.getSession().getAttribute(session_key);
		if(loginInfo != null){
			return loginInfo;
		}
		return null;
	}
	
	public static void setLoginInfo(LoginInfo loginInfo){
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		request.getSession().setAttribute(session_key,loginInfo);
	}

	/**
	 * 清除登陆信息
	 * @param uid			:userId
	 * @param xgdSessionId	:登陆分配的session
	 * @param browerSessionId:浏览器的session
	 */
	public static void clearLoginInfo(String uid,String xgdSessionId,String browerSessionId){
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		request.getSession().removeAttribute(session_key);
	}
	

}
